import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException

# 设置代理
proxy = 'https://dps.kdlapi.com/api/getdps/?secret_id=o8dwnxxu6fy8d25y7mvw&num=1&signature=n86gw540grw65csznaz351noortcx83q&pt=1&sep=1'

# 创建Chrome WebDriver，并设置请求头和代理
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://category.vip.com/suggest.php?keyword=%E9%A6%99%E6%B0%B4')
time.sleep(5)
driver.find_element_by_id('J-wp-user').click()
time.sleep(7)
while True:
    try:
        data = driver.find_element_by_xpath("//div[@class='g-row']/section[@id='J_searchCatList']").text
        driver.find_element_by_tag_name('body').send_keys(Keys.ARROW_DOWN)
        time.sleep(3)
        for _ in range(3):  # 滚动5次，根据实际情况调整
            driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
            print(data)
            next_button = driver.find_element_by_xpath("//i[@class='vipFont next-page-icon']")
            next_button.click()
            break
        time.sleep(10)
    except NoSuchElementException:
        print("找不到XPath，结束循环")
        break

# 关闭浏览器
driver.quit()
